{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import tensorflow as tf \n",
    "from PIL import Image\n",
    "from nets2 import nets_factory\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 不同字符数量\n",
    "CHAR_SET_LEN = 10\n",
    "# 图片高度\n",
    "IMAGE_HEIGHT = 60 \n",
    "# 图片宽度\n",
    "IMAGE_WIDTH = 160  \n",
    "# 批次\n",
    "BATCH_SIZE = 25\n",
    "# tfrecord文件存放路径\n",
    "TFRECORD_FILE = \"D:/Tensorflow/captcha/train.tfrecords\"\n",
    "\n",
    "# placeholder\n",
    "x = tf.placeholder(tf.float32, [None, 224, 224])  \n",
    "y0 = tf.placeholder(tf.float32, [None]) \n",
    "y1 = tf.placeholder(tf.float32, [None]) \n",
    "y2 = tf.placeholder(tf.float32, [None]) \n",
    "y3 = tf.placeholder(tf.float32, [None])\n",
    "\n",
    "# 学习率\n",
    "lr = tf.Variable(0.003, dtype=tf.float32)\n",
    "\n",
    "# 从tfrecord读出数据\n",
    "def read_and_decode(filename):\n",
    "    # 根据文件名生成一个队列\n",
    "    filename_queue = tf.train.string_input_producer([filename])\n",
    "    reader = tf.TFRecordReader()\n",
    "    # 返回文件名和文件\n",
    "    _, serialized_example = reader.read(filename_queue)   \n",
    "    features = tf.parse_single_example(serialized_example,\n",
    "                                       features={\n",
    "                                           'image' : tf.FixedLenFeature([], tf.string),\n",
    "                                           'label0': tf.FixedLenFeature([], tf.int64),\n",
    "                                           'label1': tf.FixedLenFeature([], tf.int64),\n",
    "                                           'label2': tf.FixedLenFeature([], tf.int64),\n",
    "                                           'label3': tf.FixedLenFeature([], tf.int64),\n",
    "                                       })\n",
    "    # 获取图片数据\n",
    "    image = tf.decode_raw(features['image'], tf.uint8)\n",
    "    # tf.train.shuffle_batch必须确定shape\n",
    "    image = tf.reshape(image, [224, 224])\n",
    "    # 图片预处理\n",
    "    image = tf.cast(image, tf.float32) / 255.0\n",
    "    image = tf.subtract(image, 0.5)\n",
    "    image = tf.multiply(image, 2.0)\n",
    "    # 获取label\n",
    "    label0 = tf.cast(features['label0'], tf.int32)\n",
    "    label1 = tf.cast(features['label1'], tf.int32)\n",
    "    label2 = tf.cast(features['label2'], tf.int32)\n",
    "    label3 = tf.cast(features['label3'], tf.int32)\n",
    "\n",
    "    return image, label0, label1, label2, label3\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Iter:0  Loss:1022.835  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:20  Loss:0.337  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:40  Loss:0.339  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:60  Loss:0.327  Accuracy:0.08  Learning_rate:0.0010\n",
      "Iter:80  Loss:0.328  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:100  Loss:0.340  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:120  Loss:0.327  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:140  Loss:0.331  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:160  Loss:0.329  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:180  Loss:0.331  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:200  Loss:0.333  Accuracy:0.08  Learning_rate:0.0010\n",
      "Iter:220  Loss:0.332  Accuracy:0.12  Learning_rate:0.0010\n",
      "Iter:240  Loss:0.334  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:260  Loss:0.333  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:280  Loss:0.336  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:300  Loss:0.330  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:320  Loss:0.335  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:340  Loss:0.331  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:360  Loss:0.334  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:380  Loss:0.329  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:400  Loss:0.334  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:420  Loss:0.332  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:440  Loss:0.326  Accuracy:0.08  Learning_rate:0.0010\n",
      "Iter:460  Loss:0.331  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:480  Loss:0.328  Accuracy:0.12  Learning_rate:0.0010\n",
      "Iter:500  Loss:0.328  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:520  Loss:0.342  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:540  Loss:0.330  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:560  Loss:0.331  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:580  Loss:0.328  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:600  Loss:0.334  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:620  Loss:0.330  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:640  Loss:0.338  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:660  Loss:0.337  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:680  Loss:0.330  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:700  Loss:0.329  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:720  Loss:0.333  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:740  Loss:0.328  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:760  Loss:0.333  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:780  Loss:0.332  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:800  Loss:0.328  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:820  Loss:0.333  Accuracy:0.08  Learning_rate:0.0010\n",
      "Iter:840  Loss:0.330  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:860  Loss:0.328  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:880  Loss:0.332  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:900  Loss:0.335  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:920  Loss:0.329  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:940  Loss:0.333  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:960  Loss:0.330  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:980  Loss:0.327  Accuracy:0.08  Learning_rate:0.0010\n",
      "Iter:1000  Loss:0.332  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:1020  Loss:0.328  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:1040  Loss:0.328  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1060  Loss:0.331  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1080  Loss:0.328  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1100  Loss:0.329  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1120  Loss:0.331  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1140  Loss:0.330  Accuracy:0.08  Learning_rate:0.0010\n",
      "Iter:1160  Loss:0.334  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1180  Loss:0.328  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1200  Loss:0.327  Accuracy:0.08  Learning_rate:0.0010\n",
      "Iter:1220  Loss:0.324  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1240  Loss:0.329  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1260  Loss:0.329  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1280  Loss:0.327  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1300  Loss:0.326  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1320  Loss:0.330  Accuracy:0.08  Learning_rate:0.0010\n",
      "Iter:1340  Loss:0.329  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1360  Loss:0.329  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:1380  Loss:0.328  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1400  Loss:0.328  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1420  Loss:0.327  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1440  Loss:0.332  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:1460  Loss:0.329  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:1480  Loss:0.327  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1500  Loss:0.329  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1520  Loss:0.329  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1540  Loss:0.328  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1560  Loss:0.331  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1580  Loss:0.329  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:1600  Loss:0.332  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:1620  Loss:0.330  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1640  Loss:0.329  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:1660  Loss:0.330  Accuracy:0.04  Learning_rate:0.0010\n",
      "Iter:1680  Loss:0.329  Accuracy:0.00  Learning_rate:0.0010\n",
      "Iter:1700  Loss:0.323  Accuracy:0.28  Learning_rate:0.0010\n",
      "Iter:1720  Loss:0.326  Accuracy:0.12  Learning_rate:0.0010\n",
      "Iter:1740  Loss:0.323  Accuracy:0.20  Learning_rate:0.0010\n",
      "Iter:1760  Loss:0.323  Accuracy:0.20  Learning_rate:0.0010\n",
      "Iter:1780  Loss:0.314  Accuracy:0.40  Learning_rate:0.0010\n",
      "Iter:1800  Loss:0.316  Accuracy:0.28  Learning_rate:0.0010\n",
      "Iter:1820  Loss:0.312  Accuracy:0.36  Learning_rate:0.0010\n",
      "Iter:1840  Loss:0.312  Accuracy:0.36  Learning_rate:0.0010\n",
      "Iter:1860  Loss:0.311  Accuracy:0.48  Learning_rate:0.0010\n",
      "Iter:1880  Loss:0.315  Accuracy:0.40  Learning_rate:0.0010\n",
      "Iter:1900  Loss:0.296  Accuracy:0.60  Learning_rate:0.0010\n",
      "Iter:1920  Loss:0.310  Accuracy:0.40  Learning_rate:0.0010\n",
      "Iter:1940  Loss:0.301  Accuracy:0.52  Learning_rate:0.0010\n",
      "Iter:1960  Loss:0.298  Accuracy:0.60  Learning_rate:0.0010\n",
      "Iter:1980  Loss:0.284  Accuracy:0.72  Learning_rate:0.0010\n",
      "Iter:2000  Loss:0.301  Accuracy:0.52  Learning_rate:0.0010\n",
      "Iter:2020  Loss:0.289  Accuracy:0.80  Learning_rate:0.0010\n",
      "Iter:2040  Loss:0.280  Accuracy:0.80  Learning_rate:0.0010\n",
      "Iter:2060  Loss:0.284  Accuracy:0.76  Learning_rate:0.0010\n",
      "Iter:2080  Loss:0.287  Accuracy:0.80  Learning_rate:0.0010\n",
      "Iter:2100  Loss:0.278  Accuracy:0.72  Learning_rate:0.0010\n",
      "Iter:2120  Loss:0.280  Accuracy:0.80  Learning_rate:0.0010\n",
      "Iter:2140  Loss:0.278  Accuracy:0.84  Learning_rate:0.0010\n",
      "Iter:2160  Loss:0.273  Accuracy:0.88  Learning_rate:0.0010\n",
      "Iter:2180  Loss:0.274  Accuracy:0.84  Learning_rate:0.0010\n",
      "Iter:2200  Loss:0.274  Accuracy:0.76  Learning_rate:0.0010\n",
      "Iter:2220  Loss:0.266  Accuracy:0.92  Learning_rate:0.0010\n",
      "Iter:2240  Loss:0.273  Accuracy:0.92  Learning_rate:0.0010\n",
      "Iter:2260  Loss:0.271  Accuracy:0.96  Learning_rate:0.0010\n",
      "Iter:2280  Loss:0.273  Accuracy:0.84  Learning_rate:0.0010\n",
      "Iter:2300  Loss:0.271  Accuracy:0.92  Learning_rate:0.0010\n",
      "Iter:2320  Loss:0.268  Accuracy:0.88  Learning_rate:0.0010\n",
      "Iter:2340  Loss:0.271  Accuracy:0.80  Learning_rate:0.0010\n",
      "Iter:2360  Loss:0.255  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2380  Loss:0.261  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2400  Loss:0.267  Accuracy:0.88  Learning_rate:0.0010\n",
      "Iter:2420  Loss:0.263  Accuracy:0.92  Learning_rate:0.0010\n",
      "Iter:2440  Loss:0.263  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2460  Loss:0.262  Accuracy:0.92  Learning_rate:0.0010\n",
      "Iter:2480  Loss:0.267  Accuracy:0.84  Learning_rate:0.0010\n",
      "Iter:2500  Loss:0.251  Accuracy:0.92  Learning_rate:0.0010\n",
      "Iter:2520  Loss:0.260  Accuracy:0.96  Learning_rate:0.0010\n",
      "Iter:2540  Loss:0.267  Accuracy:0.92  Learning_rate:0.0010\n",
      "Iter:2560  Loss:0.255  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2580  Loss:0.261  Accuracy:0.96  Learning_rate:0.0010\n",
      "Iter:2600  Loss:0.259  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2620  Loss:0.260  Accuracy:0.92  Learning_rate:0.0010\n",
      "Iter:2640  Loss:0.260  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2660  Loss:0.256  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2680  Loss:0.253  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2700  Loss:0.248  Accuracy:0.96  Learning_rate:0.0010\n",
      "Iter:2720  Loss:0.255  Accuracy:0.96  Learning_rate:0.0010\n",
      "Iter:2740  Loss:0.247  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2760  Loss:0.247  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2780  Loss:0.257  Accuracy:0.92  Learning_rate:0.0010\n",
      "Iter:2800  Loss:0.244  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2820  Loss:0.255  Accuracy:0.92  Learning_rate:0.0010\n",
      "Iter:2840  Loss:0.239  Accuracy:0.96  Learning_rate:0.0010\n",
      "Iter:2860  Loss:0.241  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2880  Loss:0.238  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2900  Loss:0.233  Accuracy:0.80  Learning_rate:0.0010\n",
      "Iter:2920  Loss:0.227  Accuracy:0.92  Learning_rate:0.0010\n",
      "Iter:2940  Loss:0.216  Accuracy:1.00  Learning_rate:0.0010\n",
      "Iter:2960  Loss:0.215  Accuracy:0.84  Learning_rate:0.0010\n",
      "Iter:2980  Loss:0.203  Accuracy:0.88  Learning_rate:0.0010\n",
      "Iter:3000  Loss:0.184  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:3020  Loss:0.188  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:3040  Loss:0.185  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:3060  Loss:0.177  Accuracy:1.00  Learning_rate:0.0003\n",
      "Iter:3080  Loss:0.179  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:3100  Loss:0.174  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:3120  Loss:0.178  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:3140  Loss:0.171  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:3160  Loss:0.154  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:3180  Loss:0.189  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:3200  Loss:0.173  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:3220  Loss:0.157  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:3240  Loss:0.162  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:3260  Loss:0.163  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:3280  Loss:0.146  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:3300  Loss:0.153  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:3320  Loss:0.151  Accuracy:0.96  Learning_rate:0.0003\n",
      "Iter:3340  Loss:0.120  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:3360  Loss:0.143  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:3380  Loss:0.109  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:3400  Loss:0.108  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:3420  Loss:0.116  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:3440  Loss:0.126  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:3460  Loss:0.139  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:3480  Loss:0.139  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:3500  Loss:0.110  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:3520  Loss:0.111  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:3540  Loss:0.110  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:3560  Loss:0.112  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:3580  Loss:0.120  Accuracy:0.96  Learning_rate:0.0003\n",
      "Iter:3600  Loss:0.099  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:3620  Loss:0.097  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:3640  Loss:0.088  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:3660  Loss:0.096  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:3680  Loss:0.100  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:3700  Loss:0.102  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:3720  Loss:0.086  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:3740  Loss:0.082  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:3760  Loss:0.098  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:3780  Loss:0.091  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:3800  Loss:0.090  Accuracy:0.96  Learning_rate:0.0003\n",
      "Iter:3820  Loss:0.078  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:3840  Loss:0.082  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:3860  Loss:0.063  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:3880  Loss:0.072  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:3900  Loss:0.069  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:3920  Loss:0.071  Accuracy:0.60  Learning_rate:0.0003\n",
      "Iter:3940  Loss:0.064  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:3960  Loss:0.061  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:3980  Loss:0.077  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:4000  Loss:0.070  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:4020  Loss:0.082  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:4040  Loss:0.052  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:4060  Loss:0.073  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:4080  Loss:0.082  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:4100  Loss:0.070  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:4120  Loss:0.069  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:4140  Loss:0.056  Accuracy:0.96  Learning_rate:0.0003\n",
      "Iter:4160  Loss:0.061  Accuracy:0.96  Learning_rate:0.0003\n",
      "Iter:4180  Loss:0.051  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:4200  Loss:0.070  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:4220  Loss:0.039  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:4240  Loss:0.038  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:4260  Loss:0.053  Accuracy:0.92  Learning_rate:0.0003\n",
      "Iter:4280  Loss:0.044  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:4300  Loss:0.046  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:4320  Loss:0.085  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:4340  Loss:0.057  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:4360  Loss:0.038  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:4380  Loss:0.043  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:4400  Loss:0.048  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:4420  Loss:0.045  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:4440  Loss:0.048  Accuracy:0.64  Learning_rate:0.0003\n",
      "Iter:4460  Loss:0.039  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:4480  Loss:0.042  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:4500  Loss:0.051  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:4520  Loss:0.036  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:4540  Loss:0.047  Accuracy:0.56  Learning_rate:0.0003\n",
      "Iter:4560  Loss:0.040  Accuracy:0.64  Learning_rate:0.0003\n",
      "Iter:4580  Loss:0.043  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:4600  Loss:0.031  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:4620  Loss:0.022  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:4640  Loss:0.024  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:4660  Loss:0.053  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:4680  Loss:0.029  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:4700  Loss:0.026  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:4720  Loss:0.041  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:4740  Loss:0.027  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:4760  Loss:0.031  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:4780  Loss:0.025  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:4800  Loss:0.022  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:4820  Loss:0.046  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:4840  Loss:0.050  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:4860  Loss:0.044  Accuracy:0.36  Learning_rate:0.0003\n",
      "Iter:4880  Loss:0.021  Accuracy:0.52  Learning_rate:0.0003\n",
      "Iter:4900  Loss:0.028  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:4920  Loss:0.029  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:4940  Loss:0.026  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:4960  Loss:0.031  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:4980  Loss:0.020  Accuracy:0.44  Learning_rate:0.0003\n",
      "Iter:5000  Loss:0.044  Accuracy:0.64  Learning_rate:0.0003\n",
      "Iter:5020  Loss:0.042  Accuracy:0.60  Learning_rate:0.0003\n",
      "Iter:5040  Loss:0.016  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:5060  Loss:0.028  Accuracy:0.64  Learning_rate:0.0003\n",
      "Iter:5080  Loss:0.027  Accuracy:0.60  Learning_rate:0.0003\n",
      "Iter:5100  Loss:0.025  Accuracy:0.64  Learning_rate:0.0003\n",
      "Iter:5120  Loss:0.022  Accuracy:0.64  Learning_rate:0.0003\n",
      "Iter:5140  Loss:0.026  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:5160  Loss:0.024  Accuracy:0.48  Learning_rate:0.0003\n",
      "Iter:5180  Loss:0.024  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:5200  Loss:0.019  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:5220  Loss:0.013  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:5240  Loss:0.030  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:5260  Loss:0.018  Accuracy:0.64  Learning_rate:0.0003\n",
      "Iter:5280  Loss:0.020  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:5300  Loss:0.025  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:5320  Loss:0.015  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:5340  Loss:0.031  Accuracy:0.52  Learning_rate:0.0003\n",
      "Iter:5360  Loss:0.022  Accuracy:0.64  Learning_rate:0.0003\n",
      "Iter:5380  Loss:0.040  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:5400  Loss:0.011  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:5420  Loss:0.022  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:5440  Loss:0.018  Accuracy:0.60  Learning_rate:0.0003\n",
      "Iter:5460  Loss:0.016  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:5480  Loss:0.016  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:5500  Loss:0.014  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:5520  Loss:0.018  Accuracy:0.88  Learning_rate:0.0003\n",
      "Iter:5540  Loss:0.015  Accuracy:0.64  Learning_rate:0.0003\n",
      "Iter:5560  Loss:0.023  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:5580  Loss:0.015  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:5600  Loss:0.011  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:5620  Loss:0.023  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:5640  Loss:0.011  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:5660  Loss:0.022  Accuracy:0.52  Learning_rate:0.0003\n",
      "Iter:5680  Loss:0.027  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:5700  Loss:0.015  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:5720  Loss:0.006  Accuracy:0.80  Learning_rate:0.0003\n",
      "Iter:5740  Loss:0.014  Accuracy:0.52  Learning_rate:0.0003\n",
      "Iter:5760  Loss:0.015  Accuracy:0.84  Learning_rate:0.0003\n",
      "Iter:5780  Loss:0.010  Accuracy:0.52  Learning_rate:0.0003\n",
      "Iter:5800  Loss:0.022  Accuracy:0.64  Learning_rate:0.0003\n",
      "Iter:5820  Loss:0.019  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:5840  Loss:0.014  Accuracy:0.68  Learning_rate:0.0003\n",
      "Iter:5860  Loss:0.008  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:5880  Loss:0.012  Accuracy:0.60  Learning_rate:0.0003\n",
      "Iter:5900  Loss:0.007  Accuracy:0.60  Learning_rate:0.0003\n",
      "Iter:5920  Loss:0.011  Accuracy:0.56  Learning_rate:0.0003\n",
      "Iter:5940  Loss:0.010  Accuracy:0.76  Learning_rate:0.0003\n",
      "Iter:5960  Loss:0.011  Accuracy:0.56  Learning_rate:0.0003\n",
      "Iter:5980  Loss:0.013  Accuracy:0.72  Learning_rate:0.0003\n",
      "Iter:6000  Loss:0.017  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:6020  Loss:0.008  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:6040  Loss:0.012  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:6060  Loss:0.017  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:6080  Loss:0.011  Accuracy:0.84  Learning_rate:0.0001\n",
      "Iter:6100  Loss:0.007  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:6120  Loss:0.018  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:6140  Loss:0.021  Accuracy:0.56  Learning_rate:0.0001\n",
      "Iter:6160  Loss:0.006  Accuracy:0.80  Learning_rate:0.0001\n",
      "Iter:6180  Loss:0.008  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:6200  Loss:0.006  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:6220  Loss:0.014  Accuracy:0.52  Learning_rate:0.0001\n",
      "Iter:6240  Loss:0.013  Accuracy:0.60  Learning_rate:0.0001\n",
      "Iter:6260  Loss:0.010  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:6280  Loss:0.009  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:6300  Loss:0.005  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:6320  Loss:0.011  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:6340  Loss:0.004  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:6360  Loss:0.014  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:6380  Loss:0.011  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:6400  Loss:0.012  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:6420  Loss:0.005  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:6440  Loss:0.007  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:6460  Loss:0.004  Accuracy:0.84  Learning_rate:0.0001\n",
      "Iter:6480  Loss:0.007  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:6500  Loss:0.004  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:6520  Loss:0.005  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:6540  Loss:0.013  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:6560  Loss:0.012  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:6580  Loss:0.006  Accuracy:0.56  Learning_rate:0.0001\n",
      "Iter:6600  Loss:0.005  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:6620  Loss:0.008  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:6640  Loss:0.005  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:6660  Loss:0.006  Accuracy:0.56  Learning_rate:0.0001\n",
      "Iter:6680  Loss:0.012  Accuracy:0.60  Learning_rate:0.0001\n",
      "Iter:6700  Loss:0.015  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:6720  Loss:0.004  Accuracy:0.48  Learning_rate:0.0001\n",
      "Iter:6740  Loss:0.008  Accuracy:0.56  Learning_rate:0.0001\n",
      "Iter:6760  Loss:0.003  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:6780  Loss:0.005  Accuracy:0.60  Learning_rate:0.0001\n",
      "Iter:6800  Loss:0.011  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:6820  Loss:0.010  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:6840  Loss:0.019  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:6860  Loss:0.008  Accuracy:0.48  Learning_rate:0.0001\n",
      "Iter:6880  Loss:0.013  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:6900  Loss:0.005  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:6920  Loss:0.007  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:6940  Loss:0.004  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:6960  Loss:0.010  Accuracy:0.88  Learning_rate:0.0001\n",
      "Iter:6980  Loss:0.015  Accuracy:0.80  Learning_rate:0.0001\n",
      "Iter:7000  Loss:0.005  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:7020  Loss:0.004  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:7040  Loss:0.008  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:7060  Loss:0.002  Accuracy:0.88  Learning_rate:0.0001\n",
      "Iter:7080  Loss:0.006  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:7100  Loss:0.015  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:7120  Loss:0.007  Accuracy:0.88  Learning_rate:0.0001\n",
      "Iter:7140  Loss:0.001  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:7160  Loss:0.003  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:7180  Loss:0.009  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:7200  Loss:0.011  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:7220  Loss:0.008  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:7240  Loss:0.001  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:7260  Loss:0.005  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:7280  Loss:0.002  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:7300  Loss:0.003  Accuracy:0.80  Learning_rate:0.0001\n",
      "Iter:7320  Loss:0.013  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:7340  Loss:0.005  Accuracy:0.84  Learning_rate:0.0001\n",
      "Iter:7360  Loss:0.007  Accuracy:0.92  Learning_rate:0.0001\n",
      "Iter:7380  Loss:0.002  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:7400  Loss:0.006  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:7420  Loss:0.011  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:7440  Loss:0.006  Accuracy:0.80  Learning_rate:0.0001\n",
      "Iter:7460  Loss:0.008  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:7480  Loss:0.005  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:7500  Loss:0.005  Accuracy:0.48  Learning_rate:0.0001\n",
      "Iter:7520  Loss:0.004  Accuracy:0.48  Learning_rate:0.0001\n",
      "Iter:7540  Loss:0.008  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:7560  Loss:0.007  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:7580  Loss:0.013  Accuracy:0.52  Learning_rate:0.0001\n",
      "Iter:7600  Loss:0.009  Accuracy:0.52  Learning_rate:0.0001\n",
      "Iter:7620  Loss:0.010  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:7640  Loss:0.002  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:7660  Loss:0.008  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:7680  Loss:0.011  Accuracy:0.56  Learning_rate:0.0001\n",
      "Iter:7700  Loss:0.005  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:7720  Loss:0.004  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:7740  Loss:0.003  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:7760  Loss:0.007  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:7780  Loss:0.012  Accuracy:0.80  Learning_rate:0.0001\n",
      "Iter:7800  Loss:0.002  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:7820  Loss:0.004  Accuracy:0.52  Learning_rate:0.0001\n",
      "Iter:7840  Loss:0.008  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:7860  Loss:0.008  Accuracy:0.60  Learning_rate:0.0001\n",
      "Iter:7880  Loss:0.008  Accuracy:0.52  Learning_rate:0.0001\n",
      "Iter:7900  Loss:0.007  Accuracy:0.52  Learning_rate:0.0001\n",
      "Iter:7920  Loss:0.006  Accuracy:0.84  Learning_rate:0.0001\n",
      "Iter:7940  Loss:0.004  Accuracy:0.56  Learning_rate:0.0001\n",
      "Iter:7960  Loss:0.003  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:7980  Loss:0.001  Accuracy:0.80  Learning_rate:0.0001\n",
      "Iter:8000  Loss:0.006  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:8020  Loss:0.009  Accuracy:0.80  Learning_rate:0.0001\n",
      "Iter:8040  Loss:0.004  Accuracy:0.88  Learning_rate:0.0001\n",
      "Iter:8060  Loss:0.005  Accuracy:0.80  Learning_rate:0.0001\n",
      "Iter:8080  Loss:0.011  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:8100  Loss:0.007  Accuracy:0.84  Learning_rate:0.0001\n",
      "Iter:8120  Loss:0.004  Accuracy:0.52  Learning_rate:0.0001\n",
      "Iter:8140  Loss:0.005  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:8160  Loss:0.002  Accuracy:0.52  Learning_rate:0.0001\n",
      "Iter:8180  Loss:0.002  Accuracy:0.56  Learning_rate:0.0001\n",
      "Iter:8200  Loss:0.003  Accuracy:0.48  Learning_rate:0.0001\n",
      "Iter:8220  Loss:0.001  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:8240  Loss:0.004  Accuracy:0.80  Learning_rate:0.0001\n",
      "Iter:8260  Loss:0.002  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:8280  Loss:0.008  Accuracy:0.56  Learning_rate:0.0001\n",
      "Iter:8300  Loss:0.005  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:8320  Loss:0.003  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:8340  Loss:0.010  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:8360  Loss:0.009  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:8380  Loss:0.006  Accuracy:0.52  Learning_rate:0.0001\n",
      "Iter:8400  Loss:0.000  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:8420  Loss:0.001  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:8440  Loss:0.003  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:8460  Loss:0.004  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:8480  Loss:0.007  Accuracy:0.56  Learning_rate:0.0001\n",
      "Iter:8500  Loss:0.008  Accuracy:0.60  Learning_rate:0.0001\n",
      "Iter:8520  Loss:0.011  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:8540  Loss:0.002  Accuracy:0.48  Learning_rate:0.0001\n",
      "Iter:8560  Loss:0.004  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:8580  Loss:0.002  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:8600  Loss:0.001  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:8620  Loss:0.007  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:8640  Loss:0.006  Accuracy:0.60  Learning_rate:0.0001\n",
      "Iter:8660  Loss:0.003  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:8680  Loss:0.004  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:8700  Loss:0.003  Accuracy:0.60  Learning_rate:0.0001\n",
      "Iter:8720  Loss:0.004  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:8740  Loss:0.005  Accuracy:0.76  Learning_rate:0.0001\n",
      "Iter:8760  Loss:0.002  Accuracy:0.60  Learning_rate:0.0001\n",
      "Iter:8780  Loss:0.003  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:8800  Loss:0.003  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:8820  Loss:0.003  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:8840  Loss:0.002  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:8860  Loss:0.006  Accuracy:0.72  Learning_rate:0.0001\n",
      "Iter:8880  Loss:0.002  Accuracy:0.64  Learning_rate:0.0001\n",
      "Iter:8900  Loss:0.003  Accuracy:0.60  Learning_rate:0.0001\n",
      "Iter:8920  Loss:0.004  Accuracy:0.68  Learning_rate:0.0001\n",
      "Iter:8940  Loss:0.004  Accuracy:0.84  Learning_rate:0.0001\n",
      "Iter:8960  Loss:0.001  Accuracy:0.80  Learning_rate:0.0001\n",
      "Iter:8980  Loss:0.005  Accuracy:0.52  Learning_rate:0.0001\n",
      "Iter:9000  Loss:0.005  Accuracy:0.64  Learning_rate:0.0000\n",
      "Iter:9020  Loss:0.002  Accuracy:0.56  Learning_rate:0.0000\n",
      "Iter:9040  Loss:0.006  Accuracy:0.68  Learning_rate:0.0000\n",
      "Iter:9060  Loss:0.006  Accuracy:0.84  Learning_rate:0.0000\n",
      "Iter:9080  Loss:0.002  Accuracy:0.72  Learning_rate:0.0000\n",
      "Iter:9100  Loss:0.002  Accuracy:0.64  Learning_rate:0.0000\n",
      "Iter:9120  Loss:0.003  Accuracy:0.56  Learning_rate:0.0000\n",
      "Iter:9140  Loss:0.001  Accuracy:0.72  Learning_rate:0.0000\n",
      "Iter:9160  Loss:0.001  Accuracy:0.68  Learning_rate:0.0000\n",
      "Iter:9180  Loss:0.007  Accuracy:0.72  Learning_rate:0.0000\n",
      "Iter:9200  Loss:0.007  Accuracy:0.48  Learning_rate:0.0000\n",
      "Iter:9220  Loss:0.002  Accuracy:0.76  Learning_rate:0.0000\n",
      "Iter:9240  Loss:0.006  Accuracy:0.76  Learning_rate:0.0000\n",
      "Iter:9260  Loss:0.007  Accuracy:0.52  Learning_rate:0.0000\n",
      "Iter:9280  Loss:0.004  Accuracy:0.84  Learning_rate:0.0000\n",
      "Iter:9300  Loss:0.000  Accuracy:0.60  Learning_rate:0.0000\n",
      "Iter:9320  Loss:0.004  Accuracy:0.76  Learning_rate:0.0000\n",
      "Iter:9340  Loss:0.003  Accuracy:0.68  Learning_rate:0.0000\n",
      "Iter:9360  Loss:0.005  Accuracy:0.72  Learning_rate:0.0000\n",
      "Iter:9380  Loss:0.001  Accuracy:0.40  Learning_rate:0.0000\n",
      "Iter:9400  Loss:0.004  Accuracy:0.72  Learning_rate:0.0000\n",
      "Iter:9420  Loss:0.005  Accuracy:0.72  Learning_rate:0.0000\n",
      "Iter:9440  Loss:0.008  Accuracy:0.56  Learning_rate:0.0000\n",
      "Iter:9460  Loss:0.003  Accuracy:0.64  Learning_rate:0.0000\n",
      "Iter:9480  Loss:0.003  Accuracy:0.64  Learning_rate:0.0000\n",
      "Iter:9500  Loss:0.004  Accuracy:0.60  Learning_rate:0.0000\n",
      "Iter:9520  Loss:0.001  Accuracy:0.60  Learning_rate:0.0000\n",
      "Iter:9540  Loss:0.002  Accuracy:0.68  Learning_rate:0.0000\n",
      "Iter:9560  Loss:0.000  Accuracy:0.56  Learning_rate:0.0000\n",
      "Iter:9580  Loss:0.003  Accuracy:0.64  Learning_rate:0.0000\n",
      "Iter:9600  Loss:0.003  Accuracy:0.64  Learning_rate:0.0000\n",
      "Iter:9620  Loss:0.001  Accuracy:0.72  Learning_rate:0.0000\n",
      "Iter:9640  Loss:0.003  Accuracy:0.72  Learning_rate:0.0000\n",
      "Iter:9660  Loss:0.005  Accuracy:0.68  Learning_rate:0.0000\n",
      "Iter:9680  Loss:0.003  Accuracy:0.76  Learning_rate:0.0000\n",
      "Iter:9700  Loss:0.001  Accuracy:0.72  Learning_rate:0.0000\n",
      "Iter:9720  Loss:0.001  Accuracy:0.80  Learning_rate:0.0000\n",
      "Iter:9740  Loss:0.001  Accuracy:0.68  Learning_rate:0.0000\n",
      "Iter:9760  Loss:0.005  Accuracy:0.60  Learning_rate:0.0000\n",
      "Iter:9780  Loss:0.003  Accuracy:0.44  Learning_rate:0.0000\n",
      "Iter:9800  Loss:0.001  Accuracy:0.60  Learning_rate:0.0000\n",
      "Iter:9820  Loss:0.004  Accuracy:0.68  Learning_rate:0.0000\n",
      "Iter:9840  Loss:0.003  Accuracy:0.80  Learning_rate:0.0000\n",
      "Iter:9860  Loss:0.002  Accuracy:0.68  Learning_rate:0.0000\n",
      "Iter:9880  Loss:0.000  Accuracy:0.80  Learning_rate:0.0000\n",
      "Iter:9900  Loss:0.005  Accuracy:0.72  Learning_rate:0.0000\n",
      "Iter:9920  Loss:0.001  Accuracy:0.68  Learning_rate:0.0000\n",
      "Iter:9940  Loss:0.007  Accuracy:0.68  Learning_rate:0.0000\n",
      "Iter:9960  Loss:0.010  Accuracy:0.72  Learning_rate:0.0000\n",
      "Iter:9980  Loss:0.003  Accuracy:0.80  Learning_rate:0.0000\n",
      "Iter:10000  Loss:0.004  Accuracy:0.76  Learning_rate:0.0000\n"
     ]
    }
   ],
   "source": [
    "# 获取图片数据和标签\n",
    "image, label0, label1, label2, label3 = read_and_decode(TFRECORD_FILE)\n",
    "\n",
    "#使用shuffle_batch可以随机打乱\n",
    "image_batch, label_batch0, label_batch1, label_batch2, label_batch3 = tf.train.shuffle_batch(\n",
    "        [image, label0, label1, label2, label3], batch_size = BATCH_SIZE,\n",
    "        capacity = 50000, min_after_dequeue=10000, num_threads=1)\n",
    "\n",
    "#定义网络结构\n",
    "train_network_fn = nets_factory.get_network_fn(\n",
    "    'alexnet_v2',\n",
    "    num_classes=CHAR_SET_LEN*4,\n",
    "    weight_decay=0.0005,\n",
    "    is_training=True)\n",
    " \n",
    "    \n",
    "with tf.Session() as sess:\n",
    "    # inputs: a tensor of size [batch_size, height, width, channels]\n",
    "    X = tf.reshape(x, [BATCH_SIZE, 224, 224, 1])\n",
    "    # 数据输入网络得到输出值\n",
    "    logits,end_points = train_network_fn(X)\n",
    "    \n",
    "    # 把标签转成one_hot的形式\n",
    "    one_hot_labels0 = tf.one_hot(indices=tf.cast(y0, tf.int32), depth=CHAR_SET_LEN)\n",
    "    one_hot_labels1 = tf.one_hot(indices=tf.cast(y1, tf.int32), depth=CHAR_SET_LEN)\n",
    "    one_hot_labels2 = tf.one_hot(indices=tf.cast(y2, tf.int32), depth=CHAR_SET_LEN)\n",
    "    one_hot_labels3 = tf.one_hot(indices=tf.cast(y3, tf.int32), depth=CHAR_SET_LEN)\n",
    "    \n",
    "    # 把标签转成长度为40的向量\n",
    "    label_40 = tf.concat([one_hot_labels0,one_hot_labels1,one_hot_labels2,one_hot_labels3],1)\n",
    "    # 计算loss\n",
    "    loss_40 = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=logits,labels=label_40))\n",
    "    # 优化loss\n",
    "    optimizer_40 = tf.train.AdamOptimizer(learning_rate=lr).minimize(loss_40) \n",
    "    # 计算准确率\n",
    "    correct_prediction_40 = tf.equal(tf.argmax(label_40,1),tf.argmax(logits,1))\n",
    "    accuracy_40 = tf.reduce_mean(tf.cast(correct_prediction_40,tf.float32))\n",
    "    \n",
    "    # 用于保存模型\n",
    "    saver = tf.train.Saver()\n",
    "    # 初始化\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    \n",
    "    # 创建一个协调器，管理线程\n",
    "    coord = tf.train.Coordinator()\n",
    "    # 启动QueueRunner, 此时文件名队列已经进队\n",
    "    threads = tf.train.start_queue_runners(sess=sess, coord=coord)\n",
    "\n",
    "    for i in range(10001):\n",
    "        # 获取一个批次的数据和标签\n",
    "        b_image, b_label0, b_label1 ,b_label2 ,b_label3 = sess.run([image_batch, label_batch0, label_batch1, label_batch2, label_batch3])\n",
    "        # 优化模型\n",
    "        sess.run(optimizer_40, feed_dict={x: b_image, y0:b_label0, y1: b_label1, y2: b_label2, y3: b_label3})  \n",
    "\n",
    "        # 每迭代20次计算一次loss和准确率  \n",
    "        if i % 20 == 0:  \n",
    "            # 每迭代3000次降低一次学习率\n",
    "            if i%3000 == 0:\n",
    "                sess.run(tf.assign(lr, lr/3))\n",
    "                \n",
    "            acc, loss_ = sess.run([accuracy_40,loss_40],feed_dict={x: b_image,\n",
    "                                                                  y0: b_label0,\n",
    "                                                                  y1: b_label1,\n",
    "                                                                  y2: b_label2,\n",
    "                                                                  y3: b_label3})     \n",
    "            learning_rate = sess.run(lr)\n",
    "            print (\"Iter:%d  Loss:%.3f  Accuracy:%.2f  Learning_rate:%.4f\" % (i,loss_,acc,learning_rate))\n",
    "                \n",
    "#             acc0,acc1,acc2,acc3,loss_ = sess.run([accuracy0,accuracy1,accuracy2,accuracy3,total_loss],feed_dict={x: b_image,\n",
    "#                                                                                                                 y0: b_label0,\n",
    "#                                                                                                                 y1: b_label1,\n",
    "#                                                                                                                 y2: b_label2,\n",
    "#                                                                                                                 y3: b_label3})     \n",
    "#             learning_rate = sess.run(lr)\n",
    "#             print (\"Iter:%d  Loss:%.3f  Accuracy:%.2f,%.2f,%.2f,%.2f  Learning_rate:%.4f\" % (i,loss_,acc0,acc1,acc2,acc3,learning_rate))\n",
    "             \n",
    "            # 保存模型\n",
    "            if i == 10000 : \n",
    "                saver.save(sess, \"./captcha/models/crack_captcha.model\", global_step=i)  \n",
    "                break \n",
    "                \n",
    "    # 通知其他线程关闭\n",
    "    coord.request_stop()\n",
    "    # 其他所有线程关闭之后，这一函数才能返回\n",
    "    coord.join(threads)"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
